<template>
	<view>
		<view class="scorllNav">
			<scroll-view scroll-x="true" class="navscroll">
				<view class="item " :key="item.id" v-for="(item,index) in navArr" @click="clickNav(index,item.id)" :class="index==navIndex ? 'active':''"> {{item.classname}}	</view>

			</scroll-view>
		</view>
		<!--https://ku.qingnian8.com/datalpi/news/detail.php-->
		<view class="content">
			<view v-for="item in newArr" class="row">
				<newsbox :item="item" @click.native="getDetail(item)" ></newsbox>
			</view>
		</view>
		<view class="nodata" v-if="!newArr.length">
		<!-- <image src="../../static/img/nodata.png"></image> -->
		
		</view>
		<view class="load">
			<view  v-if="(load==1)">正在请求....</view>
			<view  v-if="(load==2)">没有更多数据....</view>
			
			
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				colorList: ["blue", "red", "yellow"],
				scrollId: 1,
				navIndex:0,
				navArr:[],
				newArr:[],
				id:"",
				currentPage:1,
				load:0	 //0默认1加载中  2 没有更多数据
			}
		},
		onLoad() {
			this.getDataNav();
			this.getDataNavList();
		},
		methods: {
			clickNav(index,id){
	           this.navIndex=index;
			   this.id=id;
			   this.newArr=[];
			  this.currentPage=1;
			  this.load=0;
			   this.getDataNavList(id);
			},
			getDataNav(){
				uni.request({
					url:"https://ku.qingnian8.com/dataApi/news/navlist.php",
					success:res=>{
						console.log(res)
						this.navArr=res.data;
					}
				})
			},
			getDetail(item){
				console.log(item)
				uni.navigateTo({
					url:`/pages/tetail/tetail?cid=${item.classid}&id=${item.id}`
				})
			},
			getDataNavList(id){
				uni.request({
					url:"https://ku.qingnian8.com/dataApi/news/newslist.php",
					data:{
						cid:id,
						page:this.currentPage
					},
					success:res=>{
						console.log(res)
						if(res.data.length==0){
							this.load=2;
						}
						this.newArr=[...this.newArr,...res.data];
					}
				})
			},
			onReachBottom(){
				this.currentPage++;
					this.load=1;
				console.log("到了底部啦")
				if(this.load==2){
					return;
				}
			}
		}
	}
</script>

<style lang="scss">


	.navscroll {
		height: 100rpx;
		white-space: nowrap;
		height: 100rpx;
		background: #F7F8FA;
		position: fixed;
		left: 0;
		top: var(--window--top);
		z-index: 10;
		//去除滚动条
		::-webkit-scrollbar{
		    display: none;
		    width: 0 !important;
		    height: 0 !important;
		    -webkit-appearance: none;
		    background: transparent;
		}
	}
	.nodata{
		justify-content: center;
		 align-items: center; 
		 display: flex;
	}

	.item {
		min-width: 200rpx;
		font-size: 40rpx;
		line-height: 100rpx;
		display: inline-block;
		&.active{
			color: #31C27C;
		}
	}
	.content{
		padding: 30rpx;
		padding-top: 130rpx;
		.row{
			padding: 15rpx;
			border-bottom: 1px dotted #efefef;
		}
	}
	.load{
		text-align: center;
		font-size: 26rpx;
		color: #888;
		padding: 30rpx;
	}
</style>

<style lang="scss" scoped>

</style>